package com.jsnj33.pdaproject.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.jsnj33.pdaproject.R;
import com.jsnj33.pdaproject.bean.BatchAndProductBean;
import com.jsnj33.pdaproject.bean.PayingBillsBean;

import java.util.List;

public class AdjustmentAdapter extends RecyclerView.Adapter<AdjustmentAdapter.ViewHolder> {

    private Context mContext;
    private List<BatchAndProductBean> list;
    private boolean isShowWh = true;

    public AdjustmentAdapter(Context context,boolean isShowWh) {
        this.mContext = context;
        this.isShowWh = isShowWh;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_adjustment, parent, false);
        ViewHolder viewHolder = new ViewHolder(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {

        BatchAndProductBean batchAndProductBean = list.get(position);

        if (isShowWh){
            holder.rl_wh.setVisibility(View.VISIBLE);
            holder.tv_wh.setText(batchAndProductBean.getWh());
        }else{
            holder.rl_wh.setVisibility(View.GONE);
        }

        holder.tv_ord_no.setText(batchAndProductBean.getPrd_no());
        holder.tv_name.setText(batchAndProductBean.getPrd_name());
        holder.tv_spc.setText(batchAndProductBean.getSpc());
        holder.tv_bat_no.setText(batchAndProductBean.getBat_no());
        holder.tv_number.setText(batchAndProductBean.getSmqty()+"");
    }

    @Override
    public int getItemCount() {
        return list != null ? list.size() : 0;
    }

    public void setList(List<BatchAndProductBean> list) {
        this.list = list;
        notifyDataSetChanged();
    }

    class ViewHolder extends RecyclerView.ViewHolder {

        private TextView tv_ord_no;
        private TextView tv_name;
        private TextView tv_spc;
        private TextView tv_bat_no;
        private TextView tv_number;
        private TextView tv_wh;
        private RelativeLayout rl_wh;

        ViewHolder(View itemView) {
            super(itemView);
            tv_ord_no = itemView.findViewById(R.id.tv_ord_no);
            tv_name = itemView.findViewById(R.id.tv_name);
            tv_spc = itemView.findViewById(R.id.tv_spc);
            tv_bat_no = itemView.findViewById(R.id.tv_bat_no);
            tv_number = itemView.findViewById(R.id.tv_number);
            tv_wh = itemView.findViewById(R.id.tv_wh);
            rl_wh = itemView.findViewById(R.id.rl_wh);
        }
    }
}

